﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Internet_Deliver_Therapy.Controllers;

namespace Internet_Deliver_Therapy.Views.Index
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void Login_Click(object sender, EventArgs e)
        {
            string email = tbEmail.Text.ToString();
            string password = tbPassword.Text.ToString();
             
            UsersController userController = new UsersController();
            string loginUserAccountType = userController.login(email, password);

            if (loginUserAccountType.Length > 0)
            {
                Session["Email"] = email;
                if (loginUserAccountType.Equals("Patient"))
                {
                    Response.Redirect("~/Views/Patient/Home.aspx");
                }
                else if (loginUserAccountType.Equals("Psychologist"))
                {
                    Response.Redirect("~/Views/Psychologist/Home.aspx");
                }
                else if (loginUserAccountType.Equals("Psychiatrist"))
                {
                    Response.Redirect("~/Views/Psychiatrist/Home.aspx");
                }else if (loginUserAccountType.Equals("Admin"))
                {
                    Response.Redirect("~/Views/Admin/Home.aspx");
                }
            }
            else
            {
                ErrorMessage.Text = "Invalid username or password";
            }
            
        }
    }
}